﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    
    public partial class Form1 : Form
    {
        double num = 0, num2 = 0, result;

        int input_num;

        enum Operator { none, plus, minus, multiplication, divsion }
        Operator mode = Operator.none;
        bool isequal = false;

        public void get_parameters(int n)
        {
            if (mode == Operator.none)
            {
                num = num * 10 + n;
                label1.Text = Convert.ToString(num);
            }
            else
            {
                num2 = num2 * 10 + n;
                label2.Text = Convert.ToString(num2);
            }
        }
        public Form1()
        {
            InitializeComponent();
        }
        //未使用
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            input_num = 1;
            get_parameters(input_num);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            input_num = 2;
            get_parameters(input_num);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            input_num = 3;
            get_parameters(input_num);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            input_num = 4;
            get_parameters(input_num);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            input_num = 5;
            get_parameters(input_num);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            input_num = 6;
            get_parameters(input_num);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            input_num = 7;
            get_parameters(input_num);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            input_num = 8;
            get_parameters(input_num);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            input_num = 9;
            get_parameters(input_num);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            input_num = 0;
            get_parameters(input_num);
        }

        private void clear_Click(object sender, EventArgs e)
        {

            label1.Text = "";
            label2.Text = "";
            label3.Text = "";
            isequal = false;
            mode = Operator.none;
        }

        private void button_plus_Click(object sender, EventArgs e)
        {
            mode = Operator.plus;
            switchmode();
        }

        private void button_minus_Click(object sender, EventArgs e)
        {
            mode = Operator.minus;
            switchmode();
        }

        private void button_multiplication_Click(object sender, EventArgs e)
        {
            mode = Operator.multiplication;
            switchmode();
        }

        private void button_division_Click(object sender, EventArgs e)
        {
            mode = Operator.divsion;
            switchmode();
        }
       
        private void button_equal_Click(object sender, EventArgs e)
        {
            //等于
            switch (mode)
            {
                case Operator.plus:
                    result = num + num2;
                    break;
                case Operator.minus:
                    result = num - num2;
                    break;
                case Operator.multiplication:
                    result = num * num2;
                    break;
                case Operator.divsion:
                    result = num / num2;
                    break;
            }
            num = 0;
            num2 = 0;
            isequal = true;
            label1.Text = "";
            label2.Text = "";
            label3.Text = Convert.ToString(result);
        }


        //
        public void switchmode()
        {
            switch (mode)
            {
                case Operator.plus:
                    label2.Text = "+";
                    break;
                case Operator.minus:
                    label2.Text = "-";
                    break;
                case Operator.multiplication:
                    label2.Text = "*";
                    break;
                case Operator.divsion:
                    label2.Text = "/";
                    break;
            }
            if (isequal == true)
            {
                num = result;
            }
            label1.Text = Convert.ToString(num);
            label2.Text = Convert.ToString(num2);
        }
        }
}
